package com.ddd.app.user.executor.query;

import com.ddd.app.user.assembler.UserAssembler;
import com.ddd.client.user.dto.co.UserCO;
import com.ddd.client.user.dto.query.UserListByParamQuery;
import com.ddd.domain.user.model.entity.UserEntity;
import com.ddd.domain.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * UserListByParamQueryExe
 *
 * @author guowm
 */
@Component
public class UserListByParamQueryExe {

    @Autowired
    private UserService userService;

    public List<UserCO> execute(UserListByParamQuery userListByParamQuery) {
        List<UserEntity> userEntities = userService.findByParam(userListByParamQuery);

        return userEntities.stream()
                .map(UserAssembler::toValueObject)
                .collect(Collectors.toList());
    }
}
